<?php
namespace Dashboard\Controller;

class HeController extends BaseController{
    public function info(){
        $a        = (int)(I("currpage"));//跳转页数
        $sou      = I('sou');
        $pagesize = 15;
        if($a != null){
            $currpage = $a;
        }else{
            $currpage = isset($_GET['currpage'])?$_GET['currpage']:1;
        }
        //参数
        $table = "users_jiinfo";
        $filed = "b.end_at,b.id,b.flowers,b.covers,b.cha_nums,a.name,a.nick_name,a.sex,a.phone,a.avatar,a.img,a.age,a.shen,a.create_at";
        $join  = array("a left join __USERS__ b on a.user_id = b.id");

        if($sou){
            $content = I('content');
            $totalpage = 1;
            $currpage  = 1;
            if($sou == 1){
                $list      = joinss($table,$filed,$join,"b.name = {$content}","b.id desc");
            }
            if($sou == 2){
                $list      = joinss($table,$filed,$join,"b.phone = {$content}","b.id desc");
            }
            if($sou == 3){
                $list      = joinss($table,$filed,$join,"a.address = {$content}","b.id desc");
            }
        }else{
            $pan = I('pan');
            if($pan){
                $list      = joinss($table,$filed,$join,"a.shen = {$pan}","b.id desc");
            }else{
                $result = currpages($table,$filed,$join,"","a.id desc",$pagesize,$currpage);
                $totalpage = $result['totalpage'];
                $list      = $result['list'];
                if($result['currpage']){
                    $currpage = $result['currpage'];
                }
            }
        }
        if($list){
            foreach ($list as $k=>$v){
                if($v['age']){
                    $age              = strtotime($v['age']);
                    $list[$k]['ages'] = ages($age);
                }
                $list[$k]['img']  = explode(",",$v['img']);
                if(!$v['flowers']){ $list[$k]['flowers']  = 0;}
                if(!$v['covers']){ $list[$k]['covers']  = 0;}
                if(!$v['cha_nums']){ $list[$k]['cha_nums']  = 0;}
            }
        }
        $dai_shen = M("users_jiinfo")->join(array("a left join __USERS__ b on a.user_id = b.id"))->where("a.shen = 1")->count();
        if(!$dai_shen){$dai_shen = 0;}
        $guo = M("users_jiinfo")->join(array("a left join __USERS__ b on a.user_id = b.id"))->where("a.shen = 2")->count();
        if(!$guo){$guo = 0;}
        $ju = M("users_jiinfo")->join(array("a left join __USERS__ b on a.user_id = b.id"))->where("a.shen = 3")->count();
        if(!$ju){$ju = 0;}
        $this->assign("dai_shen",$dai_shen)->assign("guo",$guo)->assign("ju",$ju);
        $this->assign("list",$list)->assign("currpage",$currpage)->assign("totalpage",$totalpage);
        $this->display();
    }
    public function infos(){
        $id        = I('id');
        $filed     = "a.id,a.nickname,a.headimgurl,
        b.id_card,b.avatar,b.img,b.address,b.age,b.name,b.nick_name,b.sex,b.wechat,b.qq,b.shen,
        b.heights,b.weights,b.education,b.jobs,b.home,b.car,b.marriage,b.vacation,b.phone,b.child,b.moneys,b.place,
        b.smoking,b.drinking,b.marry_date,b.tags,b.xingqu,b.xingge,
        c.address as ze_address,c.heights as ze_heights,c.weights as ze_weights,c.education as ze_education,
        c.marriage as ze_marriage,c.child as ze_child,c.moneys as ze_moneys,c.smoking as ze_smoking,c.drinking as ze_drinking,
        c.home as ze_home,c.car as ze_car,c.xuanyan,c.leixing";
        $list      = joins("users",$filed,array("a left join __USERS_JIINFO__ b on a.id = b.user_id","left join __USERS_ZEINFO__ c on a.id = c.user_id"),"a.id = {$id}");
        if($list['age']){
            $age              = strtotime($list['age']);
            $list['ages'] = ages($age);
        }
        if($list['img']){
            $list['img'] = explode(",",$list['img']);
        }
        $info = user_info();
        $list['heights'] = $info['heights'][$list['heights']];
        $list['weights'] = $info['weights'][$list['weights']];
        $list['ze_heights'] = $info['heights'][$list['ze_heights']];
        $list['ze_weights'] = $info['weights'][$list['ze_weights']];
        $list['moneys'] = $info['moneys'][$list['moneys']];
        $list['ze_moneys'] = $info['moneys'][$list['ze_moneys']];
        $list['education'] = $info['education'][$list['education']];
        $list['ze_education'] = $info['education'][$list['ze_education']];

        $this->assign("list",$list);
        $this->display();
    }

    //审核操作处理
    public function he(){
        $id     = I('id');
        $status = I('type');
        $res     = up_one("users_jiinfo","user_id = {$id}",array("shen"=>$status,"up_at"=>time()));
        $data    = sel("users_jiinfo","name","user_id = {$id}");
        $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."审核了用户名为：‘{$data['name']}’,状态值为:{$status}，(1未审核2审核通过3审核失败)";
        if($res){
            $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
            $this->ajaxReturn(1);
        }else{
            $this->ajaxReturn(2);
        }
    }
}